﻿@{
    ViewBag.Title = "银联对账";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section scripts{
    <link href="~/Content/jumpto.css" rel="stylesheet" />
    <link href="~/Content/style.css" rel="stylesheet" />
    <script src="~/Scripts/jquery.AnkeExtend.js"> </script>
    <script src="~/Scripts/jquery.jumpto.js"></script>
    <script type="text/javascript">
        var station;
        var Materials = new Array();
        //页面初始化
        $(document).ready(function () {
            $(".page_container").jumpto();
            DisableBackspace();
            $('#txtStartTime').datetimebox("setValue", $.GetToday1());  //默认取今天现在。
            $('#txtEndTime').datetimebox("setValue", $.GetToday2());  //默认取今天现在。

            function EUIcombobox(jqS, o) {
                $.ajax({
                    type: "POST",
                    async: false,
                    url: o.url,
                    dataType: "JSON",
                    success: function (data1, textStatus, jqXHR) {
                        o.data = o.OneOption.concat(data1);
                        delete o.url;
                        delete o.OneOption;
                        $(jqS).combobox(o);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("获取字典数据失败！可能是已经超时，请重新登录！");
                    }
                });
            }
            bindCenterGrid();
            bindStationGrid();
        });

        function reSearchAll() {
            reSearch();
            reSearchStation("");
        }

        /*************************************************分中心汇总对账********************************************************************************/
        function bindCenterGrid() {
            $('#CenterGrid').datagrid({
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/DriverReport/GetCenterChargeCheck")',
                height: 260,
                fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                singleSelect: true,
                striped: true,
                pagination: false,//启用分页，默认每页10行
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue')
                },
                columns: [[
                     { field: "ID", hidden: true },
                    { field: "CenterCode", hidden: true },
                    { field: "CenterName", title: "分中心", width: '15%', align: "center", sortable: false, resizable: false },
                    { field: "ReceivableTotal", title: "应收合计", width: '20%', align: "center" },
                    { field: "PaidMoney", title: "实收合计", width: '20%', align: "center" },
                    {
                        field: "RecordMoney", title: "银联收费合计", width: '20%', align: "center",
                        styler: function (value, row, index) {
                            if (value != row.PaidMoney) {
                                return 'background-color:#BCF8C5;color:red;';
                            }
                        }
                    },
                {
                    field: "IFAccountCheck", title: "审核情况", width: '10%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.CenterName == "合计")
                        { return ""; }
                        //如果 已审核数量和 任务合计数量相同，就是全部已审核
                        if (value == row.ID) {
                            return "已全部审核";
                        }
                        else if (0 < value < row.ID) {
                            var num = Number(row.ID) - Number(value);
                            return "剩余审核" + num + "个";
                        }
                        else {
                            return "未审核";
                            //  return '<a  id="CtoggleCheckID" class="linkToggle" onclick="ToggleRowSubmit(\'' + row.CenterCode + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                }, {
                    field: "detail", title: "分站明细", width: '10%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.CenterName == "合计")
                        { return ""; }
                        else {
                            return '<a  id="centerDetail" class="linkDetail" onclick="centerDetailURL(\'' + row.CenterCode + '\',\'' + row.CenterName + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                }]],
                onLoadSuccess: function (data) {
                    $('.linkDetail').linkbutton({
                        text: '明细',
                        plain: true,
                        iconCls: 'icon-redo'
                    });
                    $('.linkToggle').linkbutton({
                        text: '审核',
                        plain: true,
                        iconCls: 'icon-add',
                        toggle: true
                    });
                }
            });
        }
        //查询
        function reSearch() {
            $('#CenterGrid').datagrid({
                pageNumber: 1,//点击查询返回第一页
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue'),
                }
            })
        }
        function centerDetailURL(CenterCode, CenterName) {
            // alert("传分中心编码=" + CenterCode + "用于显示分站对账明细");
            if (CenterCode) {
                $('#subCenter').html("所属分中心：(" + CenterName + ")");

                $('html,body').animate({
                    scrollTop: 790
                }, 1000, 'swing');
                reSearchStation(CenterCode);
            }
            //yh 20180111
            if(CenterCode==null || CenterCode=="")
            {
                $('#subCenter').html("所属分中心：()");

                $('html,body').animate({
                    scrollTop: 790
                }, 1000, 'swing');
                reSearchStation(CenterCode);
            }
        }

        /*******************************************分站汇总对账*************************************************************************************************/
        function bindStationGrid() {
            $('#StationGrid').datagrid({
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/DriverReport/GetStationChargeCheck")',
                height: 450,
                fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                singleSelect: true,
                striped: true,
                pagination: false,//启用分页，默认每页10行
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue'),
                    CenterCode: "",
                    //paytype: 2 //微信
                },
                columns: [[
                     { field: "ID", hidden: true },
                    { field: "StationCode", hidden: true },
                    { field: "StationName", title: "分站", width: '15%', align: "center", sortable: false, resizable: false },
                    { field: "ReceivableTotal", title: "应收合计", width: '20%', align: "center" },
                    { field: "PaidMoney", title: "实收合计", width: '20%', align: "center" },
                      {
                          field: "RecordMoney", title: "银联收费合计", width: '20%', align: "center",
                          styler: function (value, row, index) {
                              if (value != row.PaidMoney) {
                                  return 'background-color:#BCF8C5;color:red;';
                              }
                          }
                      },
                {
                    field: "IFAccountCheck", title: "财务审核", width: '10%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.StationName == "合计")
                        { return ""; }
                        if (value == row.ID) {
                            return "已全部审核";
                        }
                        else if (0 < value < row.ID) {
                            var num = Number(row.ID) - Number(value);
                            return "剩余审核" + num + "个";
                        }
                        else {
                            return "未审核";
                            //return '<a  id="toggleCheckID" class="linkToggle" onclick="ToggleRowSubmit(\'' + row.StationCode + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                }, {
                    field: "detail", title: "流水明细", width: '10%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.StationName == "合计")
                        { return ""; }
                        else {
                            return '<a  id="taskDetail" class="linkDetail" onclick="taskDetailURL(\'' + row.StationCode + '\',\'' + row.StationName + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                }]],
                onLoadSuccess: function (data) {
                    $('.linkDetail').linkbutton({
                        text: '明细',
                        plain: true,
                        iconCls: 'icon-redo'
                    });
                    $('.linkToggle').linkbutton({
                        text: '审核',
                        plain: true,
                        iconCls: 'icon-add',
                        toggle: true
                    });
                }
            });
        }
        //查询
        function reSearchStation(centerCode) {
            $('#StationGrid').datagrid({
                pageNumber: 1,//点击查询返回第一页
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue'),
                    CenterCode: centerCode,
                    //paytype: 2 //微信
                }
            })
        }
        function taskDetailURL(StationCode, StationName) {
            if (StationCode) {
                $('#subStation').html("所属分站：(" + StationName + ")");

                $('html,body').animate({
                    scrollTop: 1368
                }, 1000, 'swing');
                bindTaskGrid(StationCode);
            }
            //yh 20180111
            if (StationCode==null || StationCode=="") {
                $('#subStation').html("所属分站：()");

                $('html,body').animate({
                    scrollTop: 1368
                }, 1000, 'swing');
                bindTaskGrid(StationCode);
            }
        }

        /****************************************分站流水对账******************************************************************************************/
        //预览打印
        function bindpreview(StationCode)
        {
            var url = '@Url.Content("~/Reports/CheckPayModeWebForm.aspx?StartTime=")' + $("#txtStartTime").datetimebox('getValue') + '&EndTime=' + $("#txtEndTime").datetimebox('getValue') + '&Station=' + StationCode + '&ifCheck=' + $("#ifCheck").combobox('getValue');//传参数;
            window.open(url);
        }
        function bindTaskGrid(StationCode) {
            station = StationCode;
            $('#TaskGrid').datagrid({
                loadMsg: '数据加载中,请稍后……',
                url: '@Url.Content("~/DD/DriverReport/GetTaskChargeCheck")',
                height: 540,
                fitColumns: false, //真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
                showFooter: true,
                singleSelect: false,
                selectOnCheck: true, //如果为true，单击复选框将永远选择行。
                checkOnSelect: true,  //如果为true，当用户点击行的时候该复选框就会被选中或取消选中。
                striped: true,
                pagination: false,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 15,//设置 页容量5
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    StartTime: $("#txtStartTime").datetimebox('getValue'),
                    EndTime: $("#txtEndTime").datetimebox('getValue'),
                    Station: StationCode,
                    //paytype: 2 ,//微信
                    ifCheck: $("#ifCheck").combobox('getValue')
                },
                columns: [[
                    { field: "ID", hidden: true },
                    { field: "ck", checkbox: true },
                    { field: "StationName", title: "分站", width: '6%', align: "center", sortable: false, resizable: false },
                    { field: "ChargeTime", title: "收费时间", width: '13%', align: "center" },
                    { field: "InvoiceNumber", title: "发票号", width: '9%', align: "center" },
                    { field: "PatientName", title: "病人姓名", width: '5%', align: "center" },
                    { field: "Driver", title: "司机", width: '5%', align: "center" },
                    { field: "ReceivableTotal", title: "应收", width: '5%', align: "center" },
                    { field: "PaidCarFee", title: "车费实收", width: '5%', align: "center" },
                    { field: "PaidPRFee", title: "医疗费实收", width: '5%', align: "center" },
                    { field: "PaidMoney", title: "实收", width: '5%', align: "center" },
                    { field: "ChargeType", title: "收费方式", width: '5%', align: "center",hidden:true },
                    { field: "OutTradeNo", title: "商户订单号", width: '16%', align: "center" },
                    {
                        field: "RecordMoney", title: "银联实收", width: '8%', align: "center",
                        styler: function (value, row, index) {
                            if (value != row.PaidMoney) {
                                return 'background-color:#BCF8C5;color:red;';
                            }
                        }
                    },
                {
                    field: "IFAccountCheck", title: "财务审核", width: '7%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.StationName == "合计")
                        { return ""; }
                        if (value) {
                            return value;
                        } else {
                            return '<a  id="toggleCheckID" class="linkToggle" onclick="ToggleRowSubmit(\'' + row.ID + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                } ,
                {
                    field: "cancel", title: "", width: '7%', align: "center",
                    formatter: function (value, row, index) {
                        if (row.StationName == "合计")
                        { return ""; }
                        if (value) {
                            return value;
                        } else {
                            return '<a  id="cancelCheckID" class="linkSP" onclick="CancelRowSubmit(\'' + row.ID + '\');"  href="javascript:void(0)"></a>';
                        }
                    }
                }]],
                toolbar: [
                 {
                     id: 'btnCheck',
                     text: '批量审核',
                     iconCls: 'icon-custom-cGoods',
                     iconWidth: 22,
                     handler: function () {
                         if (Materials.length > 0) {
                             submitBatchForm(); //批量审核
                         } else {
                             $.messager.alert('系统提示', '请勾选需要审核的行', 'info', function () {
                             });
                         }
                     }
                 }
                ],
                onCheck: function (index, row) {
                    if (Materials.length == 0) {
                        Materials.push(row);
                        return;
                    }
                    var boolContain = false;
                    $.each(Materials, function (i, info) {
                        if (info.ID == row.ID) {
                            boolContain = true;
                        }
                    });
                    if (!boolContain) {
                        Materials.push(row);
                    }
                },
                onUncheck: function (index, row) {
                    var obj;
                    $.each(Materials, function (i, info) {
                        if (info.ID == row.ID) {
                            obj = info;
                        }
                    });
                    Materials.remove(obj);
                },
                onCheckAll: function (rows) {
                    $.each(rows, function (i, infos) {
                        var hasmates = false;
                        $.each(Materials, function (index, mates) {
                            if (infos.ID == mates.ID) {
                                hasmates = true;
                            }
                        });
                        if (!hasmates)
                        { Materials.push(infos); }
                    });
                },
                onUncheckAll: function (rows) {
                    var obj;
                    $.each(rows, function (i, infos) {
                        $.each(Materials, function (index, mates) {
                            if (infos.ID == mates.ID) {
                                obj = infos;
                            }
                        });
                        Materials.remove(obj);
                    });
                },
                onLoadSuccess: function (data) {
                    $('.linkSP').linkbutton({
                        text: '撤销',
                        plain: true,
                        iconCls: 'icon-custom-cJinYong'
                    });
                    $('.linkToggle').linkbutton({
                        text: '审核',
                        plain: true,
                        iconCls: 'icon-add',
                        toggle: true
                    });
                    $('#TaskGrid').datagrid('fixRowHeight');//解决行号错位
                }
            });
        }

        function reTaskSearch(StationCode) {
            if (StationCode) {
                $('#TaskGrid').datagrid({
                    pageNumber: 1,//点击查询返回第一页
                    queryParams: {
                        StartTime: $("#txtStartTime").datetimebox('getValue'),
                        EndTime: $("#txtEndTime").datetimebox('getValue'),
                        Station: StationCode,
                        //paytype: 2, //微信
                        ifCheck: $("#ifCheck").combobox('getValue')
                    }
                });
            }
        }

        /*************************************审核 相关*****************************************************************************************************/

        //任务流水财务单个审核
        function ToggleRowSubmit(rowCheckID) {
            //document.getElementById('toggleCheckID').disabled = true;
            //审核提交
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/DriverReport/SavaCheck")',
                data:
                    {
                        taskcode: rowCheckID
                    },
                dataType: "json",
                success: function (jsData) {
                    $("#TaskGrid").datagrid("reload");
                    reSearchAll();
                    $.handleJsonResult(jsData, function () {
                     //   document.getElementById('toggleCheckID').disabled = false;
                    });
                }
            });
        };

        //批量审核
        function submitBatchForm() {
            $.messager.confirm('提示', '确认批量审核吗?', function (r) {
                if (r) {
                    var jsData = new Array();
                    var i = 0;
                    var rows = $('#TaskGrid').datagrid('getChecked');

                    $(rows).each(function () {
                        var obj = new Object();
                        obj.ID = rows[i].ID;
                        obj.IFAccountCheck = "已审核";
                        jsData.push(obj);
                        i++;
                    });

                    $.ajax({
                        type: 'POST',
                        url: '@Url.Content("~/DD/DriverReport/SavaBatchCheck")',
                        data:
                            {
                                sDeliveryDetailInfo: JSON.stringify(jsData)
                            },
                        dataType: "json",
                        success: function (jsData) {
                            $.handleJsonResult(jsData, function () {
                                Materials.length = 0;
                                $("#TaskGrid").datagrid("reload");
                                reSearchAll();
                            });
                        }
                    });
                }
            })
        }

        //任务流水财务单个撤销
        function CancelRowSubmit(rowCheckID) {
            // document.getElementById('toggleCheckID').disabled = true;
            //审核撤销
            $.ajax({
                type: 'POST',
                url: '@Url.Content("~/DD/DriverReport/CancelCheck")',
                data:
                    {
                        taskcode: rowCheckID
                    },
                dataType: "json",
                success: function (jsData) {
                    $("#TaskGrid").datagrid("reload");
                    reSearchAll();
                    $.handleJsonResult(jsData, function () {
                        //document.getElementById('toggleCheckID').disabled = false;

                    });
                }
            });
        };

        /*****************************************************************************************************************************************************/
    </script>
}

<div class="main">
    <div class="page_container">
        <div class="jumpto-block">
            <h3>银联账单数据导入</h3>
            <iframe src="~/Reports/I_AccountExcelWeiXinImportWebForm.aspx" style="width:99.5%;height:200px; border:0px solid #000;"></iframe>
        </div>
        <div>
            <h3>汇总对账查询</h3>
            <p>请先输入对账日期:</p>
            <div id="search" class="easyui-layout" style="width:100%; height: 30px; margin-left: auto; margin-right: auto">
                <table style="width:99%" cellpadding="0" border="0">
                    <tr>
                        <td align="right" width="8%">开始时间：</td>
                        <td align="left" width="10%">
                            <input class="easyui-datetimebox" style="width:140px" id="txtStartTime" data-options="editable:false">
                        </td>
                        <td align="right" width="5%">结束时间：</td>
                        <td align="left" width="13%">
                            <input class="easyui-datetimebox" style="width:140px" id="txtEndTime" data-options="editable:false">
                            <a href="javascript:void(0)" id="btnSearchALL" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearchAll()">查询</a>
                        </td>
                    </tr>
                </table>
                @*<p>注意：数据匹配 请先下载相同时间区域内的数据到EXCEL导入到数据库。</p>*@
            </div>
        </div>
        <div class="jumpto-block">
            <h3>分中心汇总对账</h3>
            @*<table id="centerGrid"></table>*@

            <div id="centerTableForm" class="easyui-layout" style="width:100%; height: 300px; margin-left: auto; margin-right: auto">
                <div data-options="region:'center',title:'分中心对账',iconCls:'icon-custom-Entry'">
                    @*<div data-options="region:'center'" style="background: #fafafa; overflow: hidden">*@
                    <table id="CenterGrid"></table>
                    @*</div>*@
                </div>
            </div>
        </div>
        <div class="jumpto-block">
            <h3>分站汇总对账</h3>
            <label id="subCenter"></label>
            <div id="stationTableForm" class="easyui-layout" style="width:100%; height: 500px; margin-left: auto; margin-right: auto">
                <div data-options="region:'center',title:'分站对账',iconCls:'icon-custom-Entry'">
                    <table id="StationGrid"></table>
                </div>
            </div>
        </div>
        <div class="jumpto-block">
            <h3>分站流水对账</h3><label id="subStation"></label>
            <div id="taskTableForm" class="easyui-layout" style="width:100%; height: 600px; margin-left: auto; margin-right: auto">
                <div data-options="region:'center',title:'任务对账',iconCls:'icon-custom-Entry'">
                    <table>
                        <tr>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td align="right" valign="middle" width="8%">审核：</td>
                            <td align="right" valign="middle" width="12%">
                                <select class="easyui-combobox" style="width: 150px" id="ifCheck" data-options="panelHeight:'auto', editable:false">
                                    <option value="">全部</option>
                                    <option value="true">已审核</option>
                                    <option value="false">未审核</option>
                                </select>
                            </td>
                            <td align="center" valign="middle" width="11%">
                                <a href="javascript:void(0)" id="btnsearch" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="bindTaskGrid(station)">查询</a>
                            </td>
                            <td align="center" valign="middle" width="11%">
                                <a href="javascript:void(0)" id="btnpreview" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="bindpreview(station)">预览</a>
                            </td>
                            <td></td>
                        </tr>
                    </table>
                    <table id="TaskGrid"></table>
                </div>
            </div>
        </div>
        <div class="jumpto-block">
            <h3>自定义对账</h3>
            <div id="taskTableForm" class="easyui-layout" style="width:100%; height: 720px; margin-left: auto; margin-right: auto">
                <div data-options="region:'center'">
                    <iframe src="~/IM/I_AccountCheck/AccountCheckList" style="width: 99.5%; height: 700px; border: 0px solid #000;"></iframe>
                </div>
            </div>
        </div>
    </div>
</div>



